package collection;

import java.util.*;

public class ListDemo {
    public static void main(String[] args) {
        List<String>list=new LinkedList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println(list);

        String e =list.get(3);
        System.out.println(e);

        Iterator it = list.iterator();
        while (it.hasNext()){

            System.out.println(it.next());
        }

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        for (String str:list){
            System.out.println(str);
        }

        System.out.println(".............................................");

        list.set(3,"4");//修改下标为3的 元素
        System.out.println(list);
        String num =list.set(2,"3");
        System.out.println(list);
        System.out.println(num);

        list.remove(2);//删除下标为2的元素
        String s=list.remove(2);
        System.out.println(list);
        System.out.println(s);

        /*
        void add(int index,E e):
        将给定元素e添加到index所指定的位置
        */

        list.add(2,"three");

        System.out.println(list);


    }
}
